#include <stdio.h>
#include "Student.h"
#include <time.h>
#include "../ModuleC/Log.h"
void ReadSImformation() {//通过文件录入学生信息
	if (headS != NULL) {
		printf("学生信息已录入，请不要反复录入！\n");
		return ;
	}
	int i;
	FILE *fp;
	char filename[20];
	struct Student *p1;
	printf("请输入文件路径及文件名：\n");
	scanf("%s", filename);
	if ((fp = fopen(filename, "r")) == NULL) {
        	printf("打开文件失败！\n"); 
		return ; 
    	}
	p1 = (struct Student *)malloc(sizeof(struct Student));
	fscanf(fp, "%s %s %d", p1->SNO, p1->SN, &p1->SCN);
	for(i = 0; i < p1->SCN; i++)
		fscanf(fp, "%s", p1->SC[i]);
	fscanf(fp, "%lf", &p1->TScore);
	headS = p1;
	p1->next = NULL;
	while (!feof(fp)) { 
		p1 = (struct Student *)malloc(sizeof(struct Student));
		fscanf(fp, "%s %s %d", &p1->SNO, &p1->SN, &p1->SCN);
		for(i = 0; i < p1->SCN; i++)
			fscanf(fp, "%s", p1->SC[i]);
		fscanf(fp, "%lf\n", &p1->TScore);
		p1->next = headS->next;
		headS->next = p1;
	}   
	printf("录入学生信息成功！\n");
	fclose(fp);
	FILE *fp1;	
	fp1=fopen("FILE/log.log","a");
	Log(fp1);
	fprintf(fp1,"通过读取文件,录入了学生信息，调用了ReadSImformation()。\n");
	fclose(fp1);
}
